home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / psafm.pro < prev    next >
Text File  |  1997-07-08  |  10KB  |  354 lines

  1. ; $Id: psafm.pro,v 1.4 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ;+
  7. ; NAME:
  8. ;    PSAFM
  9. ;
  10. ; PURPOSE:
  11. ;    Given an Abobe Font metric file, this procedure generates an AFM
  12. ;    file in the format that IDL likes. This new file differs from the
  13. ;    original in the following ways:
  14. ;
  15. ;        [] Information not used by IDL is removed.
  16. ;        [] AFM files with the AdobeStandardEncoding are
  17. ;           supplemented with an ISOLatin1Encoding.
  18. ;
  19. ; CATEGORY:
  20. ;    Misc., PostScript, Fonts
  21. ;
  22. ; CALLING SEQUENCE:
  23. ;    PSAFM, input_filename, output_filename
  24. ;
  25. ; INPUTS:
  26. ;    Input_Filename:     Name of existing AFM file from Adobe.
  27. ;    Output_FIlename: Name of new AFM file to be created.
  28. ;
  29. ; OUTPUTS:
  30. ;    None.
  31. ;
  32. ; COMMON BLOCKS:
  33. ;    None.
  34. ;
  35. ; SIDE EFFECTS:
  36. ;    Generates an output file.
  37. ;
  38. ; MODIFICATION HISTORY:
  39. ;    8 January 1993, Written by AB, RSI.
  40. ;-
  41. ;
  42. ;
  43.  
  44. function PSAFM_ISOMAP
  45. ; Generate a table mapping character index to font name. Unmapped indices are
  46. ; represented by a null string.
  47.  
  48.   iso_map = strarr(256)
  49.  
  50.   ; These assignments were taken from the "PostScript Language Reference
  51.   ; Manual" Second edition, Section E.5, "Standard Roman Character Set".
  52.   ; To make trouble shooting easier, the assignments are in the same order as
  53.   ; the book. Comparing the results of these assignments to the table in
  54.   ; Section 7, "ISOLatin1Encoding Vector" reveals a few missing characters.
  55.   ; These were derived by comparing the graphic in the twop sections. These
  56.   ; extra assignments are at the end.
  57.   iso_map['101'o] = 'A'
  58.   iso_map['306'o] = 'AE'
  59.   iso_map['301'o] = 'Aacute'
  60.   iso_map['302'o] = 'Acircumflex'
  61.   iso_map['304'o] = 'Adieresis'
  62.   iso_map['300'o] = 'Agrave'
  63.   iso_map['305'o] = 'Aring'
  64.   iso_map['303'o] = 'Atilde'
  65.   iso_map['102'o] = 'B'
  66.   iso_map['103'o] = 'C'
  67.   iso_map['307'o] = 'Ccedilla'
  68.   iso_map['104'o] = 'D'
  69.   iso_map['105'o] = 'E'
  70.   iso_map['311'o] = 'Eacute'
  71.   iso_map['312'o] = 'Ecircumflex'
  72.   iso_map['313'o] = 'Edieresis'
  73.   iso_map['310'o] = 'Egrave'
  74.   iso_map['320'o] = 'Eth'
  75.   iso_map['106'o] = 'F'
  76.   iso_map['107'o] = 'G'
  77.   iso_map['110'o] = 'H'
  78.   iso_map['111'o] = 'I'
  79.   iso_map['315'o] = 'Iacute'
  80.   iso_map['316'o] = 'Icircumflex'
  81.   iso_map['317'o] = 'Idieresis'
  82.   iso_map['314'o] = 'Igrave'
  83.   iso_map['112'o] = 'J'
  84.   iso_map['113'o] = 'K'
  85.   iso_map['114'o] = 'L'
  86.   iso_map['115'o] = 'M'
  87.   iso_map['116'o] = 'N'
  88.   iso_map['321'o] = 'Ntilde'
  89.   iso_map['117'o] = 'O'
  90.   iso_map['323'o] = 'Oacute'
  91.   iso_map['324'o] = 'Ocircumflex'
  92.   iso_map['326'o] = 'Odieresis'
  93.   iso_map['322'o] = 'Ograve'
  94.   iso_map['330'o] = 'Oslash'
  95.   iso_map['325'o] = 'Otilde'
  96.   iso_map['120'o] = 'P'
  97.   iso_map['121'o] = 'Q'
  98.   iso_map['122'o] = 'R'
  99.   iso_map['123'o] = 'S'
  100.   iso_map['124'o] = 'T'
  101.   iso_map['336'o] = 'Thorn'
  102.   iso_map['125'o] = 'U'
  103.   iso_map['332'o] = 'Uacute'
  104.   iso_map['333'o] = 'Ucircumflex'
  105.   iso_map['334'o] = 'Udieresis'
  106.   iso_map['331'o] = 'Ugrave'
  107.   iso_map['126'o] = 'V'
  108.   iso_map['127'o] = 'W'
  109.   iso_map['130'o] = 'X'
  110.   iso_map['131'o] = 'Y'
  111.   iso_map['335'o] = 'Yacute'
  112.   iso_map['132'o] = 'Z'
  113.   iso_map['141'o] = 'a'
  114.   iso_map['341'o] = 'aacute'
  115.   iso_map['342'o] = 'acircumflex'
  116.   iso_map['222'o] = 'acute'
  117.   iso_map['264'o] = 'acute'
  118.   iso_map['344'o] = 'adieresis'
  119.   iso_map['346'o] = 'ae'
  120.   iso_map['340'o] = 'agrave'
  121.   iso_map['46'o] = 'ampersand'
  122.   iso_map['345'o] = 'aring'
  123.   iso_map['136'o] = 'asciicircum'
  124.   iso_map['176'o] = 'asciitilde'
  125.   iso_map['52'o] = 'asterisk'
  126.   iso_map['100'o] = 'at'
  127.   iso_map['343'o] = 'atilde'
  128.   iso_map['142'o] = 'b'
  129.   iso_map['134'o] = 'backslash'
  130.   iso_map['174'o] = 'bar'
  131.   iso_map['173'o] = 'braceleft'
  132.   iso_map['175'o] = 'braceright'
  133.   iso_map['133'o] = 'bracketleft'
  134.   iso_map['135'o] = 'bracketright'
  135.   iso_map['226'o] = 'breve'
  136.   iso_map['246'o] = 'brokenbar'
  137.   iso_map['143'o] = 'c'
  138.   iso_map['237'o] = 'caron'
  139.   iso_map['347'o] = 'ccedilla'
  140.   iso_map['270'o] = 'cedilla'
  141.   iso_map['242'o] = 'cent'
  142.   iso_map['223'o] = 'circumflex'
  143.   iso_map['72'o] = 'colon'
  144.   iso_map['54'o] = 'comma'
  145.   iso_map['251'o] = 'copyright'
  146.   iso_map['244'o] = 'currency'
  147.   iso_map['144'o] = 'd'
  148.   iso_map['260'o] = 'degree'
  149.   iso_map['250'o] = 'dieresis'
  150.   iso_map['367'o] = 'divide'
  151.   iso_map['44'o] = 'dollar'
  152.   iso_map['227'o] = 'dotaccent'
  153.   iso_map['220'o] = 'dotlessi'
  154.   iso_map['145'o] = 'e'
  155.   iso_map['351'o] = 'eacute'
  156.   iso_map['352'o] = 'ecircumflex'
  157.   iso_map['353'o] = 'edieresis'
  158.   iso_map['350'o] = 'egrave'
  159.   iso_map['70'o] = 'eight'
  160.   iso_map['75'o] = 'equal'
  161.   iso_map['360'o] = 'eth'
  162.   iso_map['41'o] = 'exclam'
  163.   iso_map['241'o] = 'exclamdown'
  164.   iso_map['146'o] = 'f'
  165.   iso_map['65'o] = 'five'
  166.   iso_map['64'o] = 'four'
  167.   iso_map['147'o] = 'g'
  168.   iso_map['337'o] = 'germandbls'
  169.   iso_map['221'o] = 'grave'
  170.   iso_map['76'o] = 'greater'
  171.   iso_map['253'o] = 'guillemotleft'
  172.   iso_map['273'o] = 'guillemotright'
  173.   iso_map['150'o] = 'h'
  174.   iso_map['235'o] = 'hungarumlaut'
  175.   iso_map['255'o] = 'hyphen'
  176.   iso_map['151'o] = 'i'
  177.   iso_map['355'o] = 'iacute'
  178.   iso_map['356'o] = 'icircumflex'
  179.   iso_map['357'o] = 'idieresis'
  180.   iso_map['354'o] = 'igrave'
  181.   iso_map['152'o] = 'j'
  182.   iso_map['153'o] = 'k'
  183.   iso_map['154'o] = 'l'
  184.   iso_map['74'o] = 'less'
  185.   iso_map['254'o] = 'logicalnot'
  186.   iso_map['155'o] = 'm'
  187.   iso_map['257'o] = 'macron'
  188.   iso_map['55'o] = 'minus'
  189.   iso_map['265'o] = 'mu'
  190.   iso_map['327'o] = 'multiply'
  191.   iso_map['156'o] = 'n'
  192.   iso_map['71'o] = 'nine'
  193.   iso_map['361'o] = 'ntilde'
  194.   iso_map['43'o] = 'numbersign'
  195.   iso_map['157'o] = 'o'
  196.   iso_map['363'o] = 'oacute'
  197.   iso_map['364'o] = 'ocircumflex'
  198.   iso_map['366'o] = 'odieresis'
  199.   iso_map['236'o] = 'ogonek'
  200.   iso_map['362'o] = 'ograve'
  201.   iso_map['61'o] = 'one'
  202.   iso_map['275'o] = 'onehalf'
  203.   iso_map['274'o] = 'onequarter'
  204.   iso_map['271'o] = 'onesuperior'
  205.   iso_map['252'o] = 'ordfeminine'
  206.   iso_map['272'o] = 'ordmasculine'
  207.   iso_map['370'o] = 'oslash'
  208.   iso_map['365'o] = 'otilde'
  209.   iso_map['160'o] = 'p'
  210.   iso_map['266'o] = 'paragraph'
  211.   iso_map['50'o] = 'parenleft'
  212.   iso_map['51'o] = 'parenright'
  213.   iso_map['45'o] = 'percent'
  214.   iso_map['56'o] = 'period'
  215.   iso_map['267'o] = 'periodcentered'
  216.   iso_map['53'o] = 'plus'
  217.   iso_map['261'o] = 'plusminus'
  218.   iso_map['161'o] = 'q'
  219.   iso_map['77'o] = 'question'
  220.   iso_map['277'o] = 'questiondown'
  221.   iso_map['42'o] = 'quotedbl'
  222.   iso_map['140'o] = 'quoteleft'
  223.   iso_map['47'o] = 'quoteright'
  224.   iso_map['162'o] = 'r'
  225.   iso_map['256'o] = 'registered'
  226.   iso_map['232'o] = 'ring'
  227.   iso_map['163'o] = 's'
  228.   iso_map['247'o] = 'section'
  229.   iso_map['73'o] = 'semicolon'
  230.   iso_map['67'o] = 'seven'
  231.   iso_map['66'o] = 'six'
  232.   iso_map['57'o] = 'slash'
  233.   iso_map['40'o] = 'space'
  234.   iso_map['243'o] = 'sterling'
  235.   iso_map['164'o] = 't'
  236.   iso_map['376'o] = 'thorn'
  237.   iso_map['63'o] = 'three'
  238.   iso_map['276'o] = 'threequarters'
  239.   iso_map['263'o] = 'threesuperior'
  240.   iso_map['224'o] = 'tilde'
  241.   iso_map['62'o] = 'two'
  242.   iso_map['262'o] = 'twosuperior'
  243.   iso_map['165'o] = 'u'
  244.   iso_map['372'o] = 'uacute'
  245.   iso_map['373'o] = 'ucircumflex'
  246.   iso_map['374'o] = 'udieresis'
  247.   iso_map['371'o] = 'ugrave'
  248.   iso_map['137'o] = 'underscore'
  249.   iso_map['166'o] = 'v'
  250.   iso_map['167'o] = 'w'
  251.   iso_map['170'o] = 'x'
  252.   iso_map['171'o] = 'y'
  253.   iso_map['375'o] = 'yacute'
  254.   iso_map['377'o] = 'ydieresis'
  255.   iso_map['245'o] = 'yen'
  256.   iso_map['172'o] = 'z'
  257.   iso_map['60'o] = 'zero'
  258.  
  259.   ; Extra assignments from Section 7.
  260.   iso_map['225'o] = 'macron'
  261.   iso_map['230'o] = 'dieresis'
  262.   iso_map['233'o] = 'cedilla'
  263.   iso_map['240'o] = 'space'
  264.  
  265.   return, iso_map
  266. end
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274. PRO PSAFM, input_file, output_file
  275. ;  on_error, 2        ; Return to caller if an error occurs
  276.   do_iso_encoding = 0
  277.   iso_map = PSAFM_ISOMAP()
  278.   iso_lines = strarr(256)
  279.   message,/INFO,'Processing ' + input_file
  280.  
  281.  
  282.   openr, in, input_file, /GET_LUN
  283.   openw, out, output_file, /GET_LUN
  284.  
  285.   printf,out,'Comment This file was generated by PSAFM.PRO for use by IDL'
  286.   printf,out,'Comment on ', systime(0), '. It may not work properly with'
  287.   printf,out,'Comment other software because it does not contain the complete'
  288.   printf,out,'Comment contents of the original file and some features are different.'
  289.   printf, out, 'Comment'
  290.  
  291.   line = ''
  292.   while not eof(in) do begin
  293.     readf, in, line
  294.     token = strcompress(line)
  295.     i = strpos(line, ' ')
  296.     if (i ne -1) then token = strmid(token, 0, i)
  297.     case token of
  298.     'Comment': do_verbatim = ((strpos(line, 'Copyright') ne -1) $
  299.                           or (strpos(line, 'Creation') ne -1))
  300.     'EncodingScheme': begin
  301.         do_verbatim = 1
  302.         if (strpos(line,'AdobeStandardEncoding') ne -1) then $
  303.             do_iso_encoding = 1
  304.         end
  305.     'FontName': do_verbatim =1
  306.     'FullName': do_verbatim =1
  307.         'StartCharMetrics': do_verbatim =1
  308.     'EndCharMetrics': do_verbatim =1
  309.     'StartFontMetrics': do_verbatim = 1
  310.     'C': begin
  311.         do_verbatim = long(strmid(line, 2, 10000)) ne -1
  312.         ; Get name and match against ISO mapping.
  313.         i = strpos(line, '; N ')
  314.         if (i ne -1) then begin
  315.           name = strmid(line, i+4, 1000)
  316.           i = strpos(name, ' ;')
  317.           if (i ne -1) then name = strmid(name, 0, i)
  318.           tmp = where(iso_map eq name, i)
  319.           for count=0,i-1 do begin
  320.         iso_lines[tmp[count]] = $
  321.           string(tmp[count],strmid(line, strpos(line, ';'), 1000), $
  322.             format='("C ", I0, X, A)')
  323.           endfor
  324.         endif
  325.         end
  326.         else: do_verbatim = 0
  327.     endcase
  328.     if (do_verbatim) then printf, out, line
  329.   endwhile
  330.  
  331.   if (do_iso_encoding) then begin
  332.     printf, out, 'Comment'
  333.     printf, out, 'Comment A real Adobe AFM file wouldn''t have a second'
  334.     printf, out, 'Comment encoding here. However, having this reduces the'
  335.     printf, out, 'Comment runtime load when switching fonts.'
  336.     printf, out, 'Comment'
  337.     printf, out, 'EncodingScheme ISOLatin1Encoding'
  338.     printf, out, 'StartCharMetrics'
  339.     for i = 0, 255 do begin
  340.     if (iso_lines[i] ne '') then begin
  341.         printf, out, iso_lines[i]
  342.     endif else if (iso_map[i] ne '') then begin
  343.         print,format='("    Unmapped ISO character: ", A, "(",O0,")")', $
  344.         iso_map[i], i
  345.     endif
  346.     endfor
  347.     printf, out, 'EndCharMetrics'
  348.   endif
  349.  
  350.   printf, out, 'EndFontMetrics'
  351.  
  352.   FREE_LUN, in, out
  353. end
  354.